﻿using InnovaApp.Portals.MVC4Portal.Models.ClientFilesGenerationModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using INNOVACALL.Framework.Common.Extensions;

namespace InnovaApp.Portals.MVC4Portal.Controllers.ClientFilesGenerationControllers
{
    public class LogXMLFileController : _ClientFilesGenerationControllers_Base
    {
        /// <summary>
        /// GET: /Logs/Latest.xml
        /// </summary>
        /// <returns></returns>
        public ActionResult Latest()
        {
            Response.ContentType = "text/xml";
            return View(GetLogXML());
        }

        public ContentResult XmlContent()
        {
            return Content(GetLogXML().XMLContent);
        }


        public LogXMLFileModel GetLogXML()
        {
            LogXMLFileModel toReturn = new LogXMLFileModel();
            string latestLogContent = Server.MapPath("MVC4Portal.log").ReadContentFile();
            latestLogContent = latestLogContent.Replace("log4net:", "");
            string xmlHeader = @"<?xml version=""1.0"" encoding=""UTF-8"" ?><events>";
            toReturn.XMLContent = string.Format("{0}{1}</events>", xmlHeader, latestLogContent);
            return toReturn;
        }
        //To imagine a language to access older logs
    }
}
